home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / PCCP024.ARJ / EMUED.C < prev    next >
C/C++ Source or Header  |  1992-05-17  |  8KB  |  274 lines

  1. /*    Copyright (C) 1992 Peter Edward Cann, all rights reserved.
  2.  */
  3.  
  4. #include<stdio.h>
  5. #include<fcntl.h>
  6. #include<sys\types.h>
  7. #include<sys\stat.h>
  8. #include<bios.h>
  9. #include<graph.h>
  10. #include"emu.h"
  11.  
  12. main(argc, argv)
  13.     int argc;
  14.     char **argv;
  15.     {
  16.     int emufd, major, minor, scan, value;
  17.     char c, fpname[256];
  18.     _settextposition(25,1);
  19.     printf("Copyright (C) 1992 Peter Edward Cann, all rights reserved.\n");
  20.     printf("You may set the environment variable PCCPPATH.\n");
  21.     printf("If not set we use the current directory.\n\n");
  22.     if(!strcmp(getenv("REMOTE"), "YES"))
  23.         {
  24.         printf("You appear to be logged in remotely, judging by the environment\n");
  25.         printf("variable REMOTE, so this is probably a very bad idea.\n");
  26.         printf("Are you sure you want to run EMUED? (y or n) --> ");
  27.         if(getchar()!='y') /* Note getchar() and not getch()! */
  28.             {
  29.             printf("I didn't think so!\n");
  30.             exit(99);
  31.             }
  32.         else
  33.             printf("OK, you're the boss!\n");
  34.         }
  35.     if(argc!=2)
  36.         {
  37.         printf("USAGE: emued <emu file basename>\n");
  38.         exit(1);
  39.         }
  40.     if(getenv("PCCPPATH")==NULL)
  41.         sprintf(fpname, "%s.emu", argv[1]);
  42.     else
  43.         sprintf(fpname, "%s\\%s.emu", getenv("PCCPPATH"), argv[1]);
  44.     if((emufd=open(fpname, O_RDONLY|O_BINARY))==-1)
  45.         {
  46.         printf("Error opening existing emu file %s for read.\nStarting from scratch.\n\n", fpname);
  47.         nullemu();
  48.         }
  49.     else if(read(emufd, &emu, sizeof(emu))!=sizeof(emu))
  50.         {
  51.         printf("Error reading existing emu file %s.\nStarting from scratch.\n\n", fpname);
  52.         nullemu();
  53.         }
  54.     if(emufd!=-1)
  55.         close(emufd);
  56.     if((emufd=open(fpname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IWRITE))==-1)
  57.         {
  58.         printf("Error opening emu file for write.\n");
  59.         exit(2);
  60.         }
  61.     printf("You should have a copy of emu.h to consult to program display functions.\n\n");
  62.     printf("Making a variable length substitution token last in a\n");
  63.     printf("function sequence is highly questionable.\n\n");
  64.     printf("tophi_p = %d {1 => top row is 24; 0 => top is 1}\n", (int)emu.tophi_p);
  65.     printf("Binary row offset = %02x\n", emu.binrowoff);
  66.     printf("Binary column offset = %02x\n", emu.bincoloff);
  67.     printf("default_wrap_p = %d\n", emu.default_wrap_p);
  68.     printf("Modify? --> ");
  69.     if(getch()=='y')
  70.         {
  71.         printf("y\nEnter tophi_p (0 or 1): --> ");
  72.         scanf("%d", &value);
  73.         emu.tophi_p=value;
  74.         printf("Enter binary row offset (hex): --> ");
  75.         scanf("%x", &value);
  76.         emu.binrowoff=value;
  77.         printf("Enter binary column offset (hex): --> ");
  78.         scanf("%x", &value);
  79.         emu.bincoloff=value;
  80.         printf("Enter default_wrap_p (0 or 1): --> ");
  81.         scanf("%d", &value);
  82.         emu.default_wrap_p=value;
  83.         }
  84.     else
  85.         printf("n\n");
  86.     while(1)
  87.         {
  88.         printf("\n\nk(ey), f(unc), g(raphics char) or e(xit)? --> ");
  89.         c=getch();
  90.         printf("%c\n", c);
  91.         if(c=='k')
  92.             {
  93.             printf("Operate the key --> ");
  94.             while(!_bios_keybrd(_KEYBRD_READY));
  95.             major=_bios_keybrd(_KEYBRD_READ);
  96.             if(major&0xff)
  97.                 printf("\n\007Not a programmable key!\n");
  98.             else
  99.                 {
  100.                 major=(major>>8)&0xff;
  101.                 printf("\nScancode 0x%02x selected.", major);
  102.                 if(emu.keys[major].nullpause_p)
  103.                     printf("  Zero presently means pause 1.1 seconds and ff means break.\n");
  104.                 else
  105.                     printf("  No special translations are in effect.\n");
  106.                 printf("Present contents (blank line means empty):\n");
  107.                 for(minor=0;minor<emu.keys[major].len;++minor)
  108.                     printf(" %02x", emu.keys[major].chars[minor]);
  109.                 printf("\nModify? (y or n): --> ");
  110.                 if(getch()=='y')
  111.                     {
  112.                     printf("y\nZero means 1.1 sec pause and ff means break? (y or n): --> ");
  113.                     if(getch()=='y')
  114.                         {
  115.                         printf("y\n");
  116.                         emu.keys[major].nullpause_p=1;
  117.                         }
  118.                     else
  119.                         {
  120.                         printf("n\n");
  121.                         emu.keys[major].nullpause_p=0;
  122.                         }
  123.                     printf("Enter chars (up to %d). INSERT to enter in hex. END to end:\n-->\n\n", KEYLEN);
  124.                     _settextposition(23,4);
  125.                     minor=0;
  126.                     while(1)
  127.                         {
  128.                         value=_bios_keybrd(_KEYBRD_READ);
  129.                         if(value==0x5200)
  130.                             {
  131.                             printf("\nEnter hex code: --> ");
  132.                             scanf("%x", &value);
  133.                             _settextposition(24,1);
  134.                             printf("\t\t\t\t\t\t\t\t\t\r");
  135.                             }
  136.                         else
  137.                             if(value==0x4f00)
  138.                                 value=END;
  139.                             else
  140.                                 value&=0xff;
  141.                         if(value==END)
  142.                             {
  143.                             printf("\n");
  144.                             emu.keys[major].len=minor;
  145.                             break;
  146.                             }
  147.                         else
  148.                             if(minor<KEYLEN)
  149.                                 {
  150.                                 emu.keys[major].chars[minor++]=value;
  151.                                 _settextposition(23,1);
  152.                                 for(scan=0;scan<minor;scan++)
  153.                                     printf(" %02x", emu.keys[major].chars[scan]);
  154.                                 printf(" -->");
  155.                                 }
  156.                             else
  157.                                 {
  158.                                 printf("\nExcess char ignored.\n");
  159.                                 emu.keys[major].len=KEYLEN;
  160.                                 break;
  161.                                 }
  162.                             }
  163.                     }
  164.                 else
  165.                     printf("n\n");
  166.                 }
  167.             }
  168.         if(c=='f')
  169.             {
  170.             printf("Sequence number (decimal): --> ");
  171.             scanf("%d", &major);
  172.             if((major<0)||(major>=NFUNCS))
  173.                 printf("Bad sequence number.\n");
  174.             else
  175.                 {
  176.                 printf("Function is presently #%d decimal.\n", emu.funcs[major].func);
  177.                 for(minor=0;emu.funcs[major].codes[minor]!=END;++minor)
  178.                     printf(" %03x", emu.funcs[major].codes[minor]);
  179.                 printf("\nModify? (y or n): --> ");
  180.                 if(getch()=='y')
  181.                     {
  182.                     printf("y\nEnter function number in decimal. --> ");
  183.                     scanf("%d", &value);
  184.                     if((value<0)||(value>NOOP))
  185.                         printf("Bad function number.\n");
  186.                     else
  187.                         {
  188.                         emu.funcs[major].func=value;
  189.                         printf("Enter chars (up to %d). INSERT to enter in hex. END at end:\n-->\n\n", FUNLEN-1);
  190.                         _settextposition(23,4);
  191.                         minor=0;
  192.                         while(1)
  193.                             {
  194.                             value=_bios_keybrd(_KEYBRD_READ);
  195.                             if(value==0x5200)
  196.                                 {
  197.                                 printf("\nEnter hex code: --> ");
  198.                                 scanf("%x", &value);
  199.                                 _settextposition(24,1);
  200.                                 printf("\t\t\t\t\t\t\t\r");
  201.                                 }
  202.                             else
  203.                                 if(value==0x4f00)
  204.                                     value=END;
  205.                                 else
  206.                                     value&=0xff;
  207.                             emu.funcs[major].codes[minor++]=value;
  208.                             if(value==END)
  209.                                 {
  210.                                 printf("\n");
  211.                                 break;
  212.                                 }
  213.                             else
  214.                                 if(minor<FUNLEN)
  215.                                     {
  216.  
  217.                                     _settextposition(23,1);
  218.                                     for(scan=0;scan<minor;scan++)
  219.                                         printf(" %03x", emu.funcs[major].codes[scan]);
  220.                                     printf(" -->");
  221.                                     }
  222.                                 else
  223.                                     {
  224.                                     minor--;
  225.                                     printf("\nExcess code ignored.\n");
  226.                                     emu.funcs[major].codes[FUNLEN-1]=END;
  227.                                     break;
  228.                                     }
  229.                             }
  230.                         }
  231.                     }
  232.                 else
  233.                     printf("n\n");
  234.                 }
  235.             }
  236.         if(c=='g')
  237.             {
  238.             printf("Enter char or INSERT to enter in hex: --> ");
  239.             value=_bios_keybrd(_KEYBRD_READ);
  240.             if(value==0x5200)
  241.                 {
  242.                 printf("Enter hex: --> ");
  243.                 scanf("%x", &value);
  244.                 }
  245.             else
  246.                 {
  247.                 value&=0xff;
  248.                 printf("%c\n", value);
  249.                 }
  250.             if(emu.gchars[value])
  251.                 printf("Hex code %02x  Current char: -->%c<--  Modify? (y or n) --> ", value, emu.gchars[value]);
  252.             else
  253.                 printf("Hex code %02x  Current char is zero (unspecified).  Modify? (y or n) --> ", value);
  254.             if(getch()=='y')
  255.                 {
  256.                 printf("y\nEnter hex code of new graphics character: --> ");
  257.                 scanf("%x", &emu.gchars[value]);
  258.                 if(emu.gchars[value])
  259.                     printf("gchar %02x hex is now: -->%c<--\n", value, emu.gchars[value]);
  260.                 else
  261.                     printf("gchar %02x hex is now zero (unspecified).\n", value);
  262.                 }
  263.             else
  264.                 printf("n\n");
  265.             }
  266.         if(c=='e')
  267.             break;
  268.         }
  269.     if(write(emufd, &emu, sizeof(emu))!=sizeof(emu))
  270.         printf("Damn!  Couldn't write the file!\n");
  271.     close(emufd);
  272.     exit(0);
  273.     }
  274.